package cn.com.bluemoon.daps.sync.core.sync.sql.mysql;

import cn.com.bluemoon.daps.common.toolkit.BmAssetUtils;
import cn.com.bluemoon.daps.sync.core.sync.sql.SqlStrBuilder;
import lombok.Data;

/**
 * @author Jarod.Kong
 * @date 2021/6/4 15:30
 */
@Data
public class MysqlChangeDefinition implements IKeyAddBlackQuote {
    private String oldColName;
    private MysqlColumnDefinition columnDefinition;
    private String preColumnName;
    private Boolean addBlackQuote = true;

    @Override
    public String toString() {
        BmAssetUtils.notNulls(new Object[]{oldColName}, "不可为空");
        SqlStrBuilder sb = new SqlStrBuilder().appendWS("change column");
        if (addBlackQuote) {
            sb.appendBQ(oldColName).appendWs();
        }else {
            sb.append(oldColName).appendWs();
        }
        sb.append(getColumnDefinition().toString());
        if (preColumnName != null) {
            sb.appendWS("after");
            if (addBlackQuote) {
                sb.appendBQ(preColumnName);
            }else {
                sb.append(preColumnName);
            }
        } else {
            sb.appendWS("first");
        }
        return sb.toString();
    }

}
